package cn.cutie.clotcache.command;

import cn.cutie.clotcache.core.ClotCache;
import cn.cutie.clotcache.core.Command;
import cn.cutie.clotcache.core.Reply;

/**
 * @Description:
 * @Author: Cutie
 * @CreateDate: 2024/6/19 20:15
 * @Version: 0.0.1
 */
public class LpopCommand implements Command {
    @Override
    public String name() {
        return "LPOP";
    }

    @Override
    public Reply<?> exec(ClotCache cache, String[] args) {
        String key = getKey(args);
        int count = 1;
        if (args.length > 6){
            String value = getValue(args);
            count = Integer.parseInt(value);
        }
        String[] ret = cache.lpop(key, count);
        return Reply.array(ret);
    }
}
